#include "StoneTowerShopItem.h"
#include "GUISystem.h"
#include <iostream>
#include <functional>

#include "TowerCreationTool.h"
#include "ToolManager.h"
#include "StoneTower.h"



StoneTowerShopItem::StoneTowerShopItem(void) : ShopItem()
{

}


StoneTowerShopItem::~StoneTowerShopItem(void)
{

}

Widget * StoneTowerShopItem::getWidget()
{
	return but;
}


void  StoneTowerShopItem::updateState(PlayerStat & stat)
{

}
void  StoneTowerShopItem::init()
{
	but = GUISystem::getPtr()->createButton();
	but->loadSkinFromFile("Data/boss.png");
	but->subsribeEvent(CLICK,new MemberSubsciber(std::tr1::bind(&StoneTowerShopItem::onClick,this)));

	tower = new StoneTower();
	tower->init();
	tower->setAmmoSpeed(5);
	tower->setRangeValue(100);
	tower->setDamageValue(70);
	tower->setShootRate(40);



}

void StoneTowerShopItem::onClick()
{
	tool = new TowerCreationTool();
	tool->setTower(tower);
	ToolManager::getPtr()->setActiveTool(tool);
}

void StoneTowerShopItem::onDestroy()
{
	GUISystem::getPtr()->deleteWidget(but);

	tower->destroy();

	delete tower;
	tower = nullptr;

	delete tool;
}